/*
 * @(#)HspUserInfoUtil.java $version 2011. 10. 14
 * 
 * Copyright 2011 NHN Corp. All rights Reserved.
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.hangame.mbl.util;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.hangame.hsp.nomad.connector.ConnectionManager;
import com.hangame.hsp.xdr.nomad_1_2.request.ReqGetSnoListByHid;
import com.hangame.hsp.xdr.nomad_1_2.response.AnsGetSnoListByHid;
import com.hangame.mbl.action.NomadConstants;
import com.hangame.mbl.model.HspUserInfo;
import com.nhncorp.lucy.common.data.DataHandlerFactory;
import com.nhncorp.lucy.common.util.ResourceLoader;

// TODO: Auto-generated Javadoc
/**
 * The Class HspUserInfoUtil.
 *
 * @author NHN
 */
public class HspUserInfoUtil {
	
	/** The log. */
	private static Log log = LogFactory.getLog(HspUserInfoUtil.class);

	/**
	 * Gets the hsp user info.
	 * 
	 * @param userIdMap the user id map
	 * @return the hsp user info
	 */
	public static Map<String, HspUserInfo> getHspUserInfo(Map<String, String> userIdMap) {
		Vector<String> userIdVector = new Vector<String>();
		List<String> userIdList = new ArrayList<String>(userIdMap.values());

		for (String userId : userIdList) {
			userIdVector.add(userId);
		}

		try {
			ConnectionManager connectionManager = ConnectionManager.getInstance();
			String mrsIniFileName = DataHandlerFactory.getDataHandler().get("mrs/ini-file");
			ResourceLoader resourceLoader = new ResourceLoader();
			File mrsIniFile = resourceLoader.getFile(mrsIniFileName);
			
			connectionManager.initialize(NomadConstants.NOMAD_MRS_ADDRESS, NomadConstants.OS_TYPE_ANDROID, new NomadResponseHandler(), mrsIniFile);

			ReqGetSnoListByHid req = new ReqGetSnoListByHid();
			req.hIdList = userIdVector;
			connectionManager.makeHeader(req.header);

			byte[] resMsg = connectionManager.syncCall(req.Save());
			AnsGetSnoListByHid res = new AnsGetSnoListByHid();
			res.Load(resMsg, 0);

			Map<String, HspUserInfo> hspUserInfoMap = new HashMap<String, HspUserInfo>();
			for (int i = 0; i < res.hIdList.size(); i++) {
				HspUserInfo hspUserInfo = new HspUserInfo();
				hspUserInfo.setNickName(res.nickNameList.get(i));
				hspUserInfo.setsNo(res.sNoList.get(i));
				hspUserInfoMap.put(res.hIdList.get(i), hspUserInfo);
			}

			return hspUserInfoMap;
		} catch (Exception e) {
			log.error("error getHspUserInfo");
			return null;
		}
	}

}
